library(haven)
library(dplyr)


########### wave 1 ############

# CITIZEN INFO
lsic_1_ci_raw=read_dta("H:/Zheng_10223/Joint/LSIC/Wave1/lsic_1_C1_F1.dta")

lsic_1_ci=lsic_1_ci_raw[,c("PERSONID","HHLDID","CI1G019")]
# IMMIGRATION INFO
lsic_1_lr_raw=read_dta("H:/Zheng_10223/Joint/LSIC/Wave1/lsic_1_LR_F1.dta")

# EMPLOYMENT INFO
lsic_1_em_raw=read_dta("H:/Zheng_10223/Joint/LSIC/Wave1/lsic_1_EM_F1.dta")

# KEEP ONLY NEEDED VARIABLES
lsic_1_lr=lsic_1_lr_raw[,c("PERSONID","HHLDID", "WT1L","LR1D005","LR1Q008","LR1Z054")]

# rename:
lsic_1_lr=lsic_1_lr %>% rename(age=LR1D005, sex=LR1Q008, intendedocc_imdb=LR1Z054 )

# keep people between 19 and 65
lsic_1_lr=lsic_1_lr %>% filter(age>18 & age<65)


lsic_1_em=lsic_1_em_raw[,c("PERSONID","EM1C005","HHLDID","EM1Q001","EM1G006","EM1Q009","EM1G025","EM1Q026","EM1C024")]

lsic_1_em=lsic_1_em %>% rename(workedbefore=EM1Q001,pastocc=EM1G006,pastocc4=EM1C005, pastocc_accepted=EM1Q009,
                               intendedocc_lsic=EM1G025,jobarranged=EM1Q026,intendedocc_lsic4=EM1C024)

# merge two sets
lsic_1=merge(lsic_1_em,lsic_1_lr,by=c("PERSONID","HHLDID"))
lsic_1=merge(lsic_1,lsic_1_ci,by=c("PERSONID","HHLDID"))

lsic_1$wave=1
lsic_1$PERSONID=NULL
lsic_1$weight=lsic_1$WT1L; lsic_1$WT1L=NULL




# LONGITUDINAL SO JUST USE WAVE 1
#
write_dta(lsic_1,"H:/Zheng_10223/Joint/LSIC/lsicwave1.dta")
